package com.tanhua.app.controller;

import com.tanhua.app.service.CommentService;
import com.tanhua.app.service.QuanziService;
import com.tanhua.domain.mongo.Publish;
import org.bson.types.ObjectId;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.aggregation.ArrayOperators;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
public class QuanziController {

    @Autowired
    private QuanziService quanziService;

            // 发布动态
    @PostMapping(value = "/movements", name = "发布动态")
    public ResponseEntity publishMovements(Publish publish, MultipartFile[] imageContent) throws IOException {

        //  给大数据做铺垫，指定动态id
        ObjectId publishId = ObjectId.get();
        publish.setId(publishId);

        // 调用service保存
        quanziService.publishMovements(publish,imageContent);

        return ResponseEntity.ok(null);
    }
    // 查询用户动态
    @GetMapping(value = "/movements/all",name = "查询用户动态")
    public ResponseEntity  findAlbumByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize",defaultValue = "10") Integer pageSize,
            Long userId){
        return quanziService.findAlbumByPage(pageNum,pageSize,userId);
    }
    //查询好友动态
    @GetMapping(value = "/movements", name = "查询好友动态")
    public ResponseEntity findTimeLineByPage(
            @RequestParam(value = "page",defaultValue = "1") Integer pageNum
           , @RequestParam(value = "pageSize" ,defaultValue = "10")Integer pageSize){
        return quanziService.findTimeLineByPage(pageNum,pageSize);
    }
    // 查询推荐动态
    @GetMapping(value = "/movements/recommend", name = "查询推荐动态")
    public ResponseEntity findRecommendByPage(
            @RequestParam(value = "page", defaultValue = "1") Integer pageNum,
            @RequestParam(value = "pagesize", defaultValue = "10") Integer pageSize) {
        return quanziService.findRecommendByPage(pageNum, pageSize);
    }
    //动态点赞
    @GetMapping(value = "/movements/{publishId}/like",name = "动态点赞")
    public ResponseEntity likePublish(@PathVariable String publishId){

        return quanziService.likePublish(publishId);

    }
    //动态点赞取消

    @GetMapping(value = "/movements/{publishId}/dislike",name = "动态取消点赞")
    public ResponseEntity dislikePublish(@PathVariable String publishId){

        return quanziService.dislikePublish(publishId);
    }
    // 动态喜欢
    @GetMapping(value = "/movements/{publishId}/love",name = "动态喜欢")
    public ResponseEntity lovePublish(@PathVariable String publishId){

        return quanziService.lovePublish(publishId);
    }
    // 动态喜欢取消
    @GetMapping(value = "/movements/{publishId}/unlove",name = "动态取消喜欢")
    public ResponseEntity unlovePublish(@PathVariable String publishId){

        return quanziService.unlovePublish(publishId);
    }
    //单条动态评论
    @GetMapping(value = "/movements/{publishId}",name = "单条动态")
    public ResponseEntity findPublishVoById(@PathVariable String publishId){
        return quanziService.findPublishVoById(publishId);
    }

    }




